package core.util;

import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

public class DailySequence extends Sequence {
	
	private Date initDate;
	
	public DailySequence() {
	}
	
	public DailySequence(long minValue, long maxValue, long increment, long startValue, boolean isCycle) {
		super(minValue, maxValue, increment, startValue, isCycle);
	}

	@Override
	public synchronized long currentValue() {
		reset();
		return super.currentValue();
	}

	@Override
	public synchronized long nextValue() {
		reset();
		return super.nextValue();
	}
	
	@Override
	protected void initialize() {
		initDate = new Date();
		super.initialize();
	}

	@Override
	protected boolean needReset() {
		if (isInitialized()) {
			return !DateUtils.isSameDay(initDate, new Date());
		}
		
		return false;
	}
}
